package com.anne.fish.service.img;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;

import com.anne.fish.Constants;
import com.anne.fish.webapp.util.DateTimeFormatUtil;

public class LocalImageUploadManager implements ImageUploadManager {

	private ImageParameter ftpParameter;

	public void setImageParameter(ImageParameter ftpParameter) {
		this.ftpParameter = ftpParameter;
	}

	 
 

	public String upload(File file, String destFileName,String uploadDir) throws Exception {

		InputStream is = new FileInputStream(file);

		 
		File dirPath = new File(uploadDir);
		if (!dirPath.exists()) {
			dirPath.mkdirs();
		}

		File destFile = new File(uploadDir + destFileName);
		OutputStream os = new FileOutputStream(destFile);
		byte[] bytefer = new byte[1000];
		int length = 0;
		while ((length = is.read(bytefer)) > 0) {
			os.write(bytefer, 0, length);
		}
		os.close();
		is.close();
		// 相对应用的路径
 		 

 
		return "";
	}

	public boolean isRemote() {
		return ftpParameter.isUsed();
	}

	public String upload(byte[] file, String destFileName ,String uploadDir) throws Exception {
		ByteArrayInputStream bis = new ByteArrayInputStream(file);

		 
		// 操作系统的绝对路径
		 
		File dirPath = new File(uploadDir);
		if (!dirPath.exists()) {
			dirPath.mkdirs();
		}

		File destFile = new File(uploadDir + destFileName);
		OutputStream os = new FileOutputStream(destFile);
		byte[] bytefer = new byte[1000];
		int length = 0;
		while ((length = bis.read(bytefer)) > 0) {
			os.write(bytefer, 0, length);
		}
		os.close();
		bis.close();
		// 相对应用的路径
 

		return "";
	}

	public ImageParameter getImageParameter() {
		return ftpParameter;
	}

}
